home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 February / enter-2006-02.iso / files / Illustrator_CS2_ue_TryOut.exe / bridge / Adobe Bridge 1.0.msi / Data1.cab / bridge.jsx < prev    next >
Encoding:
Text File  |  2005-03-24  |  6.2 KB  |  236 lines

  1. // (c) Copyright 2004.  Adobe Systems, Incorporated.  All rights reserved.
  2.  
  3. // This JavaScript is to be read by Bridge, Photoshop, and other Adobe apps at
  4. // launch. It generally exposes a larger Bridge dom to the other apps.
  5.  
  6. // debug level: 0-2 (0:disable, 1:break on error, 2:break at beginning)
  7. $.level = 0;
  8. // debugger; // launch debugger on next line
  9.  
  10.  
  11.  
  12. //=================================================================
  13. // Setup/Support
  14. // This first portion of the script sets up an object to provide
  15. // scope for all Bridge BridgeTalk related routines to prevent
  16. // name collision with other groups' scripts, and defines some common
  17. // utility functions.
  18. //=================================================================
  19.  
  20. var bridge = new Object;
  21.  
  22. //-----------------------------------------------------------------
  23. // This routine tries to return an array of File objects created
  24. // from the 'files' argument. It will convert a single File object
  25. // or a single string into an array of File objects, or it will
  26. // convert an array of string and File objects into an array of
  27. // file objects.
  28. //-----------------------------------------------------------------
  29. bridge.ExtractFileArray = function (files)
  30. {
  31.     var fileArray = new Array;
  32.     
  33.     // If it isn't an array, make it a length one array.
  34.     if (!(files instanceof Array))
  35.         files = new Array (files);
  36.     
  37.     // Turn each item in the array into a File, or remove it.
  38.     for (index = 0; index < files.length; ++index)
  39.     {
  40.         var file = files[index];
  41.         
  42.         if (file instanceof File)
  43.             fileArray.push (file);
  44.         else if (typeof file == 'string')
  45.             fileArray.push (File (file));
  46.         else
  47.         {
  48.             // do nothing
  49.         }
  50.     }
  51.     
  52.     return fileArray;
  53. }
  54.  
  55. bridge.convertPathStrToFile = function( file )
  56. {
  57.     return File( file );
  58. }
  59.  
  60. //=================================================================
  61. // CrossDOM/X-DOM
  62. // Implements Bridge's cross DOM API - the a small set of
  63. // operations that are common to all Adobe apps.
  64. //=================================================================
  65.  
  66.  
  67. //-----------------------------------------------------------------
  68. // executeScript (script) - Performs an "eval" on the given script.
  69. //
  70. // return value        undefined
  71. //
  72. // script            String        The script to be evaled
  73. //-----------------------------------------------------------------
  74.  
  75. bridge.executeScript = function( script )
  76. {
  77.     if( BridgeTalk.appName != "bridge" )
  78.     {
  79.         // Bring Bridge to front if already running
  80.         BridgeTalk.bringToFront( "bridge" );
  81.  
  82.         var bt = new BridgeTalk;
  83.         bt.target = "bridge";
  84.         bt.body = script;
  85.         bt.send();
  86.     }
  87.     else
  88.     {
  89.         // Bring Bridge to front if already running
  90.         app.bringToFront();
  91.         eval( script );
  92.     }
  93. }
  94.  
  95. //-----------------------------------------------------------------
  96. // open (files) - Performs the equivalent of File->New Window on the
  97. // requested paths. Accepts either an Array object or a single
  98. // path.
  99. //
  100. // return value     undefined
  101. //            
  102. // files            File or Array of File    files to display in new Window
  103. //-----------------------------------------------------------------
  104.  
  105. bridge.open = function( files )
  106. {
  107.     if( BridgeTalk.appName == "bridge" )
  108.     {        
  109.         var fileArray = bridge.ExtractFileArray ( files ); 
  110.         
  111.         for ( index = 0; index < fileArray.length; ++index )
  112.         {
  113.             var file = fileArray[index];
  114.             
  115.             app.browseTo( file );
  116.         }
  117.         
  118.         app.bringToFront();
  119.     }
  120.     else
  121.     {
  122.         var fileArray = bridge.ExtractFileArray ( files );
  123.         
  124.         var bt = new BridgeTalk;
  125.         bt.target = "bridge";
  126.         bt.body = "bridge.open( " + fileArray.toSource() + " );";
  127.         bt.send();
  128.     }
  129. }
  130.  
  131. //-----------------------------------------------------------------
  132. // openAsNew ([creation-options]*) - Performs the equivalent of
  133. // File->New Window. The creation-options are app-specific and should
  134. // ideally map on to the app's new() function. Bridge has no creation
  135. // options. Opens a new Bridge Window to the default path.
  136. //
  137. // return value        undefined
  138. //-----------------------------------------------------------------
  139.  
  140. bridge.openAsNew = function()
  141. {
  142.     if( BridgeTalk.appName == "bridge" )
  143.     {
  144.         if( app.documents.length == 0 )
  145.             app.browseTo();
  146.         else
  147.             app.browseTo( app.document.thumbnail.path );
  148.  
  149.         app.bringToFront();
  150.     }
  151.     else
  152.     {
  153.         var bt = new BridgeTalk;
  154.         bt.target = "bridge";
  155.         
  156.         if( BridgeTalk.isRunning( "bridge" ) )
  157.             bt.body = "bridge.openAsNew()";
  158.         else
  159.             bt.body = "app.document.thumbnail = new Thumbnail( app.document.thumbnail.path );";
  160.         
  161.         bt.send();    
  162.     }
  163. }
  164.  
  165. //-----------------------------------------------------------------
  166. // print (files) - Performs the equivalent of File->Print on the
  167. // requested files. Bridge has no such functionality.
  168. //
  169. // return value            undefined            
  170. // files                File or Array of File    files to be printed
  171. //-----------------------------------------------------------------
  172.  
  173. bridge.print = function( files )
  174. {
  175.     //do nothing. Bridge does not print
  176. }
  177.  
  178. //-----------------------------------------------------------------
  179. // reveal (file) - Gives the target app focus and brings the
  180. // specified document to the foreground if it is already open.
  181. // Scrolls the file into view in the Bridge content pane.
  182. //
  183. // return value        undefined
  184. //
  185. // file                File        file to be revealed
  186. //-----------------------------------------------------------------
  187.  
  188. bridge.reveal = function( file )
  189. {
  190.     if( BridgeTalk.appName == "bridge" )
  191.     {
  192.         if( typeof file == "string" )
  193.             file = bridge.convertPathStrToFile( file );
  194.         
  195.         var fileThumb = new Thumbnail( file );
  196.             
  197.         for( var i = 0; i < app.documents.length; i++ )
  198.         {
  199.             var thumbs = app.documents[i].thumbnail.children;
  200.             
  201.             if( thumbs.length > 0 )
  202.                 for( var j = 0; j < thumbs.length; j++ )
  203.                 {
  204.                     if( thumbs[j].spec.fsName == fileThumb.spec.fsName )
  205.                     {
  206.                         app.documents[i].bringToFront();
  207.                         app.documents[i].reveal( fileThumb );
  208.                     }
  209.                 }
  210.         }
  211.     }
  212.     else
  213.     {        
  214.         if( typeof file == "string" )
  215.             file = bridge.convertPathStrToFile( file );
  216.             
  217.         var bt = new BridgeTalk;
  218.         bt.target = "bridge";
  219.         bt.body = "bridge.reveal(" + file.toSource() + ");";
  220.         bt.send();    
  221.     }
  222. }
  223.  
  224. //-----------------------------------------------------------------
  225. // quit () - Performs the equivalent of File->Exit or Quit Bridge.
  226. //
  227. //    return value    undefined
  228. //-----------------------------------------------------------------
  229.  
  230. bridge.quit = function()
  231. {
  232.     if( BridgeTalk.isRunning( "bridge" ) )
  233.         bridge.executeScript( "app.quit();" );
  234. }
  235.  
  236.